<?php

class Core_Model_DbTable_Buoys extends Zend_Db_Table_Abstract {

    protected $_name = 'buoy';

    public function getAll() {
        $buoys = $this->fetchAll();
        if ($buoys->count() > 0) {
            $port_ids = array();
            foreach ($buoys as $buoy) {
                $port_ids[] = $buoy->port;
            }
            $port_db = new Core_Model_DbTable_Ports();
            $ports = $port_db->getPortsForBuoys($port_ids);
            foreach ($buoys as $buoy) {
                if (isset($ports[$buoy->port])) {
                    $buoy->port = $ports[$buoy->port];
                }
            }
        }
        return $buoys;
    }

    public function getDetail($bid) {
        $cond = $this->getAdapter()->quoteInto("id = (?)", $bid);
        return $this->fetchRow($cond);
    }

    public function batchDelete($ids) {
        $cond = $this->getAdapter()->quoteInto("id in (?)", $ids);
        return $this->delete($cond);
    }

    public function getBuoyByPort($port_id) {
        return $this->fetchAll($this->getAdapter()->quoteInto("port = (?)", $port_id));
    }

}

?>
